// packageJ/eyeDevice/entering/entering.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    eyeLeft: '',
    eyeRight: '',
    date: '',
    show: false,
    minDate: new Date(new Date().getFullYear(), 0, 1).getTime(),
    maxDate: new Date().getTime(),
    nowData: new Date().getTime(),

    stamped_at: '',
    l_naked_vision: '',
    l_myopic_spherical_mirror: '',
    l_myopic_column_mirror: '',
    l_eye_axis: '',
    l_eye_pressure: '',
    l_corneal_curvature: '',
    l_far_view_ball_mirror: '',
    l_far_view_ball_column: '',
    r_naked_vision: '',
    r_myopic_spherical_mirror: '',
    r_myopic_column_mirror: '',
    r_eye_axis: '',
    r_eye_pressure: '',
    r_corneal_curvature: '',
    r_far_view_ball_mirror: '',
    r_far_view_ball_column: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(new Date().getFullYear())
    wx.setNavigationBarTitle({
      title: '手动录入',
    })
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  showTap() {
    this.setData({
      show: true
    });
  },
  onConfirm(event) {
    this.setData({
      show: false,
      nowData: Date.parse(event.detail)
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      stamped_at: '',
      l_naked_vision: '',
      l_myopic_spherical_mirror: '',
      l_myopic_column_mirror: '',
      l_eye_axis: '',
      l_eye_pressure: '',
      l_corneal_curvature: '',
      l_far_view_ball_mirror: '',
      l_far_view_ball_column: '',
      r_naked_vision: '',
      r_myopic_spherical_mirror: '',
      r_myopic_column_mirror: '',
      r_eye_axis: '',
      r_eye_pressure: '',
      r_corneal_curvature: '',
      r_far_view_ball_mirror: '',
      r_far_view_ball_column: '',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getData() {
    let json = {
      stamped_at: parseInt(this.data.nowData / 1000),
      l_naked_vision: this.data.l_naked_vision,
      l_myopic_spherical_mirror: this.data.l_myopic_spherical_mirror,
      l_myopic_column_mirror: this.data.l_myopic_column_mirror,
      l_eye_axis: this.data.l_eye_axis,
      l_eye_pressure: this.data.l_eye_pressure,
      l_corneal_curvature: this.data.l_corneal_curvature,
      l_far_view_ball_mirror: this.data.l_far_view_ball_mirror,
      l_far_view_ball_column: this.data.l_far_view_ball_column,
      r_naked_vision: this.data.r_naked_vision,
      r_myopic_spherical_mirror: this.data.r_myopic_spherical_mirror,
      r_myopic_column_mirror: this.data.r_myopic_column_mirror,
      r_eye_axis: this.data.r_eye_axis,
      r_eye_pressure: this.data.r_eye_pressure,
      r_corneal_curvature: this.data.r_corneal_curvature,
      r_far_view_ball_mirror: this.data.r_far_view_ball_mirror,
      r_far_view_ball_column: this.data.r_far_view_ball_column,
    }
    wx.showLoading({
      title: '加载中',
    })
    let urlStr = app.getNetAddresss("plugin.eye-device.frontend.modules.archive.controllers.store.index");
    app._postNetWork({
      url: urlStr,
      data: json,
      success: (resdata) => {
        let res = resdata.data
        wx.hideLoading();
        if (res.result == 1) {
          // console.log(res)
          app.tips(res.msg)
          wx.showToast({
            title: res.msg,
            duration: 1000,
            icon: 'none',
            success: (resa) => {
              setTimeout(() => {
                // wx.navigateTo({
                //   url: '/packageJ/eyeDevice/eyesightRecord/index',
                // })
                wx.navigateBack({
                  delta:1
                })
              }, 1000);
            }
          })
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {}
    });
  },
  checkRule() {
    if (app._isTextEmpty(this.data.l_naked_vision)) {
      app.tips("请输入裸眼视力(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_naked_vision)) {
      app.tips("请输入裸眼视力(右眼)")
      return
    }
    if (app._isTextEmpty(this.data.l_myopic_spherical_mirror)) {
      app.tips("请输入近视球镜(D)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_myopic_spherical_mirror)) {
      app.tips("请输入近视球镜(D)(右眼)")
      return
    }
    if (app._isTextEmpty(this.data.l_myopic_column_mirror)) {
      app.tips("请输入近视柱镜(D)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_myopic_column_mirror)) {
      app.tips("请输入近视柱镜(D)(右眼")
      return
    }
    if (app._isTextEmpty(this.data.l_eye_axis)) {
      app.tips("请输入眼轴(mm)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_eye_axis)) {
      app.tips("请输入眼轴(mm)(右眼)")
      return
    }
    if (app._isTextEmpty(this.data.l_eye_pressure)) {
      app.tips("请输入眼压(mmHg)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_eye_pressure)) {
      app.tips("请输入眼压(mmHg)(右眼)")
      return
    }
    if (app._isTextEmpty(this.data.l_corneal_curvature)) {
      app.tips("请输入角膜曲率(D)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_corneal_curvature)) {
      app.tips("请输入角膜曲率(D)(右眼)")
      return
    }
    if (app._isTextEmpty(this.data.l_far_view_ball_mirror)) {
      app.tips("请输入远视球镜(D)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_far_view_ball_mirror)) {
      app.tips("请输入远视球镜(D)(右眼)")
      return
    }
    if (app._isTextEmpty(this.data.l_far_view_ball_column)) {
      app.tips("请输入远视柱镜(D)(左眼)")
      return
    }
    if (app._isTextEmpty(this.data.r_far_view_ball_column)) {
      app.tips("请输入远视柱镜(D)(右眼)")
      return
    }
    this.getData()
  }
})